#!/usr/bin/env node

const buf = new Buffer(256);
buf[0] =23;

console.log('buffer length:',buf.length);
console.log('\nbuffer content:',buf);

for(var i = 0;i < 256;i++) {
    buf[i]=i;
}
console.log('\nbuffer content:',buf);

const end = buf.slice(246,256);
console.log('\nbuf\'s end 6 items:', end);

end.fill(0);
console.log('\nbuf\'s end 6 items:', end);

// 数组实例化
const array = ['a',0xba,0xdf,0x00,255,10];
const buf1 = new Buffer(array);
console.log('\nbuf1:', buf1.length,buf1);
//字符串实例化
const buf2 = new Buffer('hello world', 'utf8');
console.log('\nbuf2:',buf2.length,buf2.toString());

const buf3 = new Buffer(buf2.length);
buf2.copy(buf3,0,0,buf2.length);
console.log('\nbuf3:',buf3.length, buf3.toString());


//上课检查打印字符串  utf8  utf16
const buf4 = Buffer.from('123');
console.log('\nbuf4:',buf4);

let buf5 = Buffer.from('hello','utf8');
console.log('\nbuf5:',buf5);

let buf6 = Buffer.from('hello,你好','utf16le');
console.log('\nbuf6:',buf6);